package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.BookMarks;
import org.example.pojo.Comment;
import org.example.pojo.Like;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface BookMarksMapper {
    @Insert("insert into bookmarks(user_id,group_id,url,title,description,fav_icon_url,asterisk) values(#{userId},#{groupId},#{url},#{title},#{description},#{favIconUrl},#{asterisk})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addBookMarks(BookMarks bookMarks);
    List<BookMarks> bookMarksList(Integer userId,
                                  String keywords, Integer asterisk, Integer groupId, Integer tagId, String begin, String end);
    @Select("select * from bookmarks where id=#{id}")
    BookMarks bookMarkDetail(Integer id);

    void delBookMarks(List<Integer> ids);
    void setAsterisk(Integer asterisk, List<Integer> ids);

    void editBookMarks(BookMarks bookMarks);
    @Delete("delete from bookmarks where group_id=#{groupId}")
    void deleteByGroupId(Integer groupId);
    @Insert("insert into comment(bookmark_id, user_id, content) values(#{bookmarkId}, #{userId}, #{content})")
    void addComment(Comment comment);
    @Delete("delete from comment where id=#{id} and user_id=#{userId}")
    void delComment(Comment comment);
    @Select("select * from comment where bookmark_id=#{bookmarkId}")
    List<Comment> getCommentsByBookmarkId(Integer bookmarkId);
    @Insert("insert into likes(user_id, bookmark_id) values(#{userId}, #{bookmarkId})")
    void addLike(Like like);
    @Delete("delete from likes where bookmark_id=#{bookmarkId} and user_id=#{userId}")
    void cancelLike(Like like);
    @Select("select count(*) from likes where bookmark_id=#{bookmarkId}")
    Integer getLikeCountByBookmarkId(Integer bookmarkId);
    @Select("select count(*) from likes where bookmark_id=#{bookmarkId} and user_id=#{userId}")
    Integer getLikeStatus(Like like);
}
